//
//  SqureTroopForm.cpp
//  fingeradvanture
//
//  Created by shuaibincheng on 16/5/9.
//
//

#include "SquareTroopForm.hpp"

void SquareTroopForm::group()
{
    auto screenWidth = Director::getInstance()->getVisibleSize().width;
    auto screenHeight = Director::getInstance()->getVisibleSize().height;
    
    auto x = screenWidth / 2, y = screenHeight;
    
    for(auto it = members->begin(); it != members->end(); it++)
    {
        (*it)->setPosition(x, y);
    }
    
    auto first = members->at(0);
    auto radius = first->getAnchorPoint().y * first->getContentSize().height;
    troopSize.width = 2 * radius;
    troopSize.height = 2 * radius;
    troopVisibleSize.width = screenWidth;
    troopVisibleSize.height = screenHeight;
    
    int end = monsterInCenter()?(members->size() - 1):members->size();
    auto step  = 360.0f / end;
    for(int i = 0; i < end; i++)
    {
        members->at(i)->setRotation(i * step);
    }
}

void SquareTroopForm::train()
{
    getAction()->train(*members);
}

float SquareTroopForm::marginLeft()
{
    return (troopVisibleSize.width - troopSize.width) / 2;
}

float SquareTroopForm::marginRight()
{
    return (troopVisibleSize.width - troopSize.width) / 2;
}

std::vector<TroopStyleType> SquareTroopForm::allowedTroopStyles()
{
    std::vector<TroopStyleType> types;
    types.push_back(TYPE_CIRCLE);
    return types;
}

std::vector<TroopActionStyle> SquareTroopForm::allowedTroopActionStyle()
{
    std::vector<TroopActionStyle> types;
    types.push_back(TYPE_CIRCLEFORM);
    return types;
}

bool SquareTroopForm::monsterInCenter()
{
    return members->size() % 2;
}

